﻿using System;

namespace Wisdom.Core
{
    /// <summary>
    /// 描述：异常处理类型
    /// </summary>
    /// <typeparam name="TException">被异常处理类型.</typeparam>
    public abstract class ExceptionHandler<TException> : IExceptionHandler
        where TException : Exception
    {
        #region Protected Methods
        /// <summary>
        /// 执行内部异常处理
        /// </summary>
        /// <param name="ex">被处理的异常.</param>
        /// <returns>True 异常处理成功, 否则, false.</returns>
        protected abstract bool DoHandle(TException ex);
        #endregion

        #region Public Methods
        /// <summary>
        /// 处理指定异常
        /// </summary>
        /// <param name="ex">被处理的异常.</param>
        /// <returns>True 异常处理成功, 否则, false.</returns>
        public virtual bool HandleException(Exception ex)
        {
            return DoHandle(ex as TException);
        }
        #endregion
    }
}
